[codex] Structure ACP schema generator errors#3362
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
ApprovabilityVerdict: Approved This PR refactors error handling in a code generation script by converting unstructured errors into typed Effect error classes. The changes are mechanical, don't alter the core logic flow, and include comprehensive tests for the new error structures. You can customize Macroscope's approvability policy. Learn more. |
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
15152d6 to
162cbae
Compare
Dismissing prior approval to re-evaluate 162cbae
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Schema errors thrown not yielded
- Converted collectSchemaEntries from a plain function using throw to an Effect.fn generator using yield*, so AcpGeneratorSchemaValueDeclarationMissingError and AcpGeneratorSchemaNameParseError become typed failures instead of defects.
Or push these changes by commenting:
@cursor push d506182388
Preview (d506182388)
diff --git a/packages/effect-acp/scripts/generate.ts b/packages/effect-acp/scripts/generate.ts
--- a/packages/effect-acp/scripts/generate.ts
+++ b/packages/effect-acp/scripts/generate.ts
@@ -313,9 +313,7 @@
yield* fs.writeFileString(metaOutputPath, metaOutput);
});
-function collectSchemaEntries(
- chunk: string,
-): ReadonlyArray<{ readonly name: string; readonly code: string }> {
+const collectSchemaEntries = Effect.fn("collectSchemaEntries")(function* (chunk: string) {
const lines = chunk
.split("\n")
.map((line) => line.trim())
@@ -330,14 +328,14 @@
const constLine = lines[index + 1];
if (!constLine?.startsWith("export const ")) {
- throw new AcpGeneratorSchemaValueDeclarationMissingError({
+ return yield* new AcpGeneratorSchemaValueDeclarationMissingError({
typeDeclaration: typeLine,
});
}
const match = /^export type ([A-Za-z0-9_]+)/.exec(typeLine);
if (!match?.[1]) {
- throw new AcpGeneratorSchemaNameParseError({ typeDeclaration: typeLine });
+ return yield* new AcpGeneratorSchemaNameParseError({ typeDeclaration: typeLine });
}
entries.push({
@@ -348,7 +346,7 @@
}
return entries;
-}
+});
function normalizeNullableTypes(value: Schema.Json): Schema.Json {
if (Array.isArray(value)) {
@@ -431,7 +429,7 @@
const output = generator.generate("openapi-3.1", normalizedDefinitions as never, false).trim();
if (output.length > 0) {
- for (const entry of collectSchemaEntries(output)) {
+ for (const entry of yield* collectSchemaEntries(output)) {
if (!generatedEntries.has(entry.name)) {
generatedEntries.set(entry.name, entry.code);
}You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 162cbae. Configure here.
Co-authored-by: codex <codex@users.noreply.github.com>
d92c31b
into
codex/redact-dpop-request-target
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>


Summary
Validation
vp test packages/effect-acp/scripts/generate.test.ts --no-cachevp check(passes with pre-existing warnings)vp run typecheckvpr typecheckOverlap audit
No current open PR touches either changed path, including previous filenames.
Note
Low Risk
Changes are confined to the dev-time schema generator script and its tests; success paths are unchanged aside from safer error shapes and download cleanup ordering.
Overview
Replaces the generic
GenerateCommandErrorin the ACP schema generator with EffectSchema.TaggedErrorclasses for download (HTTP vs filesystem), upstream JSON decode,bun oxfmtformatting, and malformed generated schema lines.Download-related failures attach redacted URL context via
getUrlDiagnosticsfrom@t3tools/shared(length, protocol, hostname only—no full URL, credentials, or query in errors or messages). Underlying HTTP, FS, decode, and process failures are kept incausefields with path, stage, and command metadata where useful.downloadSchemasnow registers the temp-file cleanup finalizer before starting downloads so partial failures still remove downloaded assets. Several pipeline steps are exported and covered by a newgenerate.test.tssuite. The CLI entrypoint is gated withimport.meta.mainso importing the script no longer runs the command.Reviewed by Cursor Bugbot for commit a559447. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Structure ACP schema generator errors with tagged error types and safe URL diagnostics
TaggedErrorclasses for each failure stage: HTTP download, filesystem write, document decode, formatter process/exit, and schema entry parsing.decodeUpstreamSchemaDocument,decodeMetaDocument,formatGeneratedFiles, andcollectSchemaEntriesinto exported Effect functions with structured failure types.if (import.meta.main)guard so importing the module no longer auto-runs the generate command.collectSchemaEntriesis now an Effect and callers must bind it;generateSchemasnow propagates typed errors instead ofGenerateCommandError.Macroscope summarized a559447.